import router from './index'
// 进度条
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

NProgress.configure({
  ease: 'ease',
  speed: 500,
})

/* 前端路由跳转 */
router.beforeEach((to, from, next) => {
  NProgress.start()
  const token = sessionStorage.getItem('token')
  if (!token && to.name !== 'login') {
    next({ name: 'login' })
  } else if (token && to.name === 'login') {
    next({ name: 'home' })
  } else {
    next()
  }
})
router.afterEach((transition) => {
  NProgress.done()
})

export default router
